package utils;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import java.io.*;

public class saveAsExcelUtils {
    /**
     * 将你的数据保存为excel,调用该方法需要三个参数，所以在执行前必须提供下面三个参数
     * @param filepath 目标存储文件夹
     * @param fpPlus 你想存储的名字
     * @param hf 一个excell对象
     */
    public static void saveAsExcel(String filepath, String fpPlus, HSSFWorkbook hf) {
        String str = filepath + fpPlus;
        File file = new File(str);
        if (file.exists()) {
            file.deleteOnExit();
            file = new File(str);
        }
        OutputStream outputStream = null;
        try {
            outputStream = new FileOutputStream(file);
            try {
                hf.write(outputStream);
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } finally {
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }


}
